package com.jshop.seckill.web.service.impl;

import com.jshop.seckill.domain.UserAddress;
import com.jshop.seckill.http.HttpResult;
import com.jshop.seckill.mapper.AddressMapper;
import com.jshop.seckill.web.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 * @Author yaxiongliu
 **/
@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    AddressMapper addressMapper;

    @Override
    public UserAddress findByAid(Integer id) {
        return addressMapper.findById(id);
    }


    @Override
    public HttpResult addAddress(UserAddress userAddress) {
        int result=addressMapper.addAddress(userAddress);
        //看插入结果是否大于0条，如果满足则返回成功，不满足返回失败
        return result>0 ? HttpResult.ok():HttpResult.error();
    }

    @Override
    public List<UserAddress> getAddrByUserId(Integer userId) {
        return addressMapper.getAddrByUserId(userId);
    }

    @Override
    public HttpResult updateAddress(UserAddress userAddress) {
        int result=addressMapper.updateAddress(userAddress);
        //看更新结果是否大于0条，如果满足则返回成功，不满足返回失败
        return result>0 ? HttpResult.ok():HttpResult.error();
    }

    @Override
    public HttpResult deleteById(Integer addressId) {
        int result=addressMapper.deleteById(addressId);
        //看删除结果是否大于0条，如果满足则返回成功，不满足返回失败
        return result>0 ? HttpResult.ok():HttpResult.error();
    }
}
